<template>
	<!-- 添加弹框 -->
	<el-dialog title="" size='tiny' :visible.sync="dialogTableVisible" class="wrap" @close="cancel" :close-on-click-modal="false">
		<i class="el-icon-close close" @click="cancel" style="color: white;z-index:10"></i>
	    <div class="bt">添加排课</div>
		<el-form label-width="100px" class="form">
			<el-form-item label="班级">
				<el-select v-model="vbjid" class="select-block">
							<el-option :label="v.mc" :value="v.id" v-for="v in bjboxlist"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="老师">
					<el-select v-model="vlsid" class="select-block" >
								<el-option :label="v.mc" :value="v.id" v-for="v in lsboxlist"></el-option>
					</el-select>
			</el-form-item>

			<el-form-item label="教室">
				<el-select v-model="vjsid" class="select-block" @change="getsjdlist">
							<el-option :label="v.jsmc" :value="v.id " v-for="v in jsboxlist"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="时间段">
				<el-select v-model="vsjdid" class="select-block" >
							<el-option :label="v.sjd" :value="v.id" v-for="v in sjdboxlist"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="开始时间">
				<el-date-picker class="select-block"  v-model="vkssj"  type="date"  placeholder="选择日期"  ></el-date-picker>
			</el-form-item>
			<el-form-item label="课时数量">
				<el-input v-model="vkssl" placeholder="请输入课时数量" icon="add" class="select-block"></el-input>
			</el-form-item>
			<el-form-item label="上课周期">
				<el-checkbox-group v-model="checkList"  >
			    <el-checkbox class="check" label="1">星期一</el-checkbox>
			    <el-checkbox class="check" label="2">星期二</el-checkbox>
			    <el-checkbox class="check" label="3">星期三</el-checkbox>
			    <el-checkbox class="check" label="4">星期四</el-checkbox>
			    <el-checkbox class="check" label="5">星期五</el-checkbox>
			    <el-checkbox class="check" label="6">星期六</el-checkbox>
			    <el-checkbox class="check" label="7">星期日</el-checkbox>
			  </el-checkbox-group>
			</el-form-item>
		</el-form>
		<el-button type="info" class="submit" @click="submit">保存</el-button>
	</el-dialog>
</template>
<script type="text/javascript">
	import qs from 'qs'
	export default {
		data() {
			return {
				vbjid: '',
				vlsid: '',
				vjsid: '',
				vkcid: '',
				vsjdid: '',
				vkssj:'',
				vkssl:'',
				checkList:[],

				// vgh: '',
				// vsjdid: '',
				// vsj: '',
				// vdklsgh: '',
				// vdkls: '',
				// vissk: '',
				// visdkjs: '',
				// vskday: '',
				dialogTableVisible: true,
				bjboxlist:[],
				lsboxlist:[],
				// kcboxlist:[],
				jsboxlist:[],
				sjdboxlist:[],

			}
		},
		created () {
				this.getlslist()
				this.getbjlist(); //加载下拉列表
				// this.getkclist()
				this.getjslist(); //加载下拉列表

		},
		methods: {
			getlslist(){
				var logininfo = JSON.parse(localStorage.logininfo) ;
					this.axios.get(this.$store.state.api + 'ls/getlslist',{
						params: {
							yhid: logininfo.id,
							xxid: logininfo.xxid
						}
					}).then( res => {
						// console.log(121222)
						console.log(res)
							let data = res.data.data.list;
							this.lsboxlist = data;
					}).catch( res => {
					})
			},
			getbjlist(){
				var logininfo = JSON.parse(localStorage.logininfo) ;
					this.axios.get(this.$store.state.api + 'bj/getbj',{
						params: {
								yhid: logininfo.id + '',
								xxid: logininfo.xxid + ''
						}
					}).then( res => {
						// console.log(1212)
						console.log(res)
							let data = res.data.data.list;
							this.bjboxlist = data;
					}).catch( res => {
					})
			},
			// getkclist(){
			// 	var logininfo = JSON.parse(localStorage.logininfo) ;
			// 		this.axios.get(this.$store.state.api + 'fxkc/mc',{
			// 		}).then( res => {
			// 			// console.log(1212)
			// 			// console.log(res)
			// 				let data = res.data.data;
			// 				this.kcboxlist = data;
			// 		}).catch( res => {
			// 		})
			// },
			getjslist(){
				var logininfo = JSON.parse(localStorage.logininfo) ;
					// this.searchLoading = true;
					this.axios.get(this.$store.state.api + 'xxjs/mc',{

					}).then( res => {
						console.log(1)
							console.log(res)
							let data = res.data.data;
							this.jsboxlist = data;
							getsjdlist()
					}).catch( res => {
					})
			},
			getsjdlist(){
				this.vsjdid = ''
				var logininfo = JSON.parse(localStorage.logininfo) ;
					this.searchLoading = true;
					this.axios.get(this.$store.state.api + 'jssjd/mc',{
							params:{
									jsid:this.vjsid
							}
					}).then( res => {
						console.log(12)
							console.log(res)
							// this.sjdboxlist = res;
							let data = res.data.data;
							this.sjdboxlist = data;
					}).catch( res => {
					})
			},
			submit() {
				//检测
				// alert(this.checkList)
				this.$store.state.loading = true;
			   /* if(!this.mc) {
					this.$message.warning('请填写分类名称');
					this.$store.state.loading = false;
					return;
				} */
				var logininfo = JSON.parse(localStorage.logininfo);
				var params3 = qs.stringify({
						bjid:this.vbjid,
						jsid:this.vjsid,
						lsid:this.vlsid,
						// kcid:this.vkcid,
						yhid:logininfo.id,
						xxid:logininfo.xxid,
						sjdid:this.vsjdid,
						bjtime:this.vkssj,
						kscnt:this.vkssl,
						weekstr:this.checkList+'',
				});
				//执行
				this.axios.post(this.$store.state.api + 'pk/Pkplpk', params3)
					.then(res => {
						if(res.data.code == 1) {
							this.$emit('close', { type: 'add', cancel: false });
							this.$store.state.loading = false;
						} else {
							this.$emit('close', { type: 'add', cancel: false });
							this.$store.state.loading = false;
						}
					}).catch(res => {
						this.$message.warning("服务器繁忙，请重试");
						//this.$emit('close', { type: 'add', cancel: false });
						this.$store.state.loading = false;
					})
			},
			cancel() {
				this.$emit('close', { type: 'add', cancel: true })
			}
		}
	}
</script>
<style lang="less" scoped>
	.wrap {
		.input-block {
			margin-bottom: 20px;
			text-align: center;
		}
		.bt{
			position: absolute;
			width: 100%;
			height: 50px;
			margin: 0 auto;
			top: 0;
			left: 0;
			background: #50BFFF;
			color:white;
			text-align:left;
			line-height: 50px;
			font-size: 17px;
			padding-left: 15px;
		}
		.input {
			width: 280px;
			display: inline-block;
		}
		.input-block span {
			display: inline-block;
			width: 70px;
			text-align: right;
			padding-right: 10px;
		}
		.submit {
			width: 120px;
			display: block;
			margin: 0 auto;
			margin-top: 20px;
		}
		.check{
			margin: 0;

		}
		.select-block{
			width: 85%;
		}
	}
</style>
